#include "Eagle.h"
#include "EcoSystem.h"
#include "Environment.h"
#include<iostream>

Eagle::Eagle(EcoSystem *eco_system) : Consumer(eco_system)
{
    set_alive();
    set_max_hp(20000);
    set_hp(get_max_hp()/2);
    set_init_speed(15.0);
    set_speed(get_init_speed());
    set_life_span(LIFE_SPAN[get_species_id()] * (1 + max(min(0.2, EcoSystem::random_double() - 0.5), -0.2)));
}
Eagle::~Eagle() {}

const unsigned int Eagle::get_species_id() const
{
    return EAGLE_SPECIES_ID;
}


Gdiplus::Image *Eagle::get_entity_image() const
{
    static Gdiplus::Image *img = Gdiplus::Image::FromFile(L".\\images\\eagle_l.png");
    static Gdiplus::Image *img_r = Gdiplus::Image::FromFile(L".\\images\\eagle_r.png");

    if ((get_position() - get_prev_position()).x < 0)
        return img;
    else
        return img_r;
}

Entity *Eagle::new_entity() const
{
    return new Eagle(eco_system);
}

void Eagle::on_tick()
{
    set_age(get_age() + 1);

    if (get_age() >get_life_span())
        set_dead();

    set_hp(get_hp() - get_speed() * get_speed() / 2);
    multiply();

    if (!prey(get_init_speed()))
        random_motion(get_init_speed()*0.5);

    /*if (go_left())
        is_go_left = true;
    else
        is_go_left = false;*/

    Environment *ptr = eco_system->get_environment_instance();
    if (ptr->get_temperature() > 30.0 || ptr->get_temperature() < 5.0){
        set_hp(get_hp()*0.8);
    }

    if (ptr->get_brightness() < 0.3)
        set_speed(get_speed()*0.8);
    else if (ptr->get_brightness() < 0.1 || ptr->get_weather() == 4)
        set_speed(get_speed()*0.5);
}

int    Eagle::get_cost_of_being_preyed() const
{
    return get_hp()*0.15;
}
int    Eagle::get_gain_after_being_preyed() const
{
    return get_hp()*0.2;
}